package Demo01.test2;
import java.util.Arrays;
class Book01 implements Comparable<Book01>{
    private String title;
    private double price;
    public Book01(String title,double price){
        this.title = title;
        this.price = price;
    }
    public String toString(){
        return "【Book】图书名称：" + this.title +"、图书价格" + this.price + "\n";
    }
    @Override
    public int compareTo(Book01 o){
        if (this.price > o.price){
            return 1;
        }else if (this.price < o.price){
            return  -1;
        }else {
            return 0;
        }
    }
}
public class ComparableDemo01 {
    private static void main(String[] args) throws Exception{
        Book01 books [] = new Book01[]{
                new Book01("Java从入门到项目实战", 99.8),
                new Book01("Python从入门到项目实战", 89.7),
                new Book01("Go从入门到项目实战", 96.3)};
        Arrays.sort(books);
        System.out.println(Arrays.toString(books));
    }
}
